* Send a requested AUDIO FILE or PLAYLIST to user from a redirected /ext/audio request
* this script is used for file access from embeded or external audio players
*
* 3 kind of audio file can be processed :
* - audio files (.mp3, .wav...)
* - existing playlist (.m3u files)
* - PHP playlist (used by audio explorer scripts), named *playlist*.m3u[.xml]
* - single mp3 playlist (used by audio explorer scripts),named *singleMP3*.mp3.xml, used to bypass flash player limitation (cannot read somme characters like "&"...)
* if a .xml extension is added on a m3u or a mp3 file, the actual output is converted to an XML playlist file designed for being red by flash player.
*
* All (mime) video files can be processed. Only simple "streaming" is supported (no playlist or XML stuff...)
*
* URI must be formated like "/external/sess_$id/[audio/$bitrate/]urlencoded($filename)
* where "$id" is an active session id, and "urlencoded(filename)" is url-encoded requested
* file name (must include absolute path, and not relative path)
*
* If audio/$bitrate/ is specified, output file is reencoded with FFMPEG encoder
*
* If $filename is an existing m3u file, an modified m3u is sent to user, replacing song's filenames by
* reformated filenames (/external/sess_$id/...)
*
* If $fileName is *playlist*.m3u or *playlist*.m3u.xml,
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
// If link is not published audio or streamed direct link, exit
if(!(@$token=$tokenList[$id])) cfLog('invalid published video id ('.$id.')',LOG_DBG);
if($token['type']!=='publishAudio' && ($token['type']!=='directLink' || @$token['streaming']!=='audio')) cfLog('invalid published audio id ('.$id.')',LOG_DBG);
if(!isset($uri['file'])) die();
$files=array();
// Generate playlist from directory content
if(is_dir($token['filename'])){
foreach (cfGlob($token['filename'].'/*.*') as $cfn){
if($range && strpos($range,'-')!==false && $range!='0-' && !$resampledAudioFile/* iPhone resampled content: 416 is sent by cfRangeAccessibleOutputSend function */){
// Reject range requests on resampled files or m3u or xml
if(!$acceptRange){
header('HTTP/1.1 416 Requested Range Not Satisfiable');
if(cfBGetVar('name')!=='iPhone') header('Content-Disposition: inline; filename="'.cfUTF8Encode(basename($completeFilename),false,false).(($outputCodec=='wmpMobile')?WMP_MOBILE_AUDIO_EXT:'').'"'); // iPhone doesn't like this header...